package cyan.gf.field;


import cyan.gf.db.TableField;
import cyan.gf.util.NameUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by cyan on 2017/2/2.
 * Email:qsyan@vip.qq.com
 */
public class OracleFieldWarpper implements FieldWarpper {

  public TableField warpperd(ResultSet rs) throws SQLException {
    String fieldText, typeText, nullable;
    fieldText = rs.getString(1);
    typeText = rs.getString(2);
    nullable = rs.getString(3);
    TableField tableField = new TableField();
    tableField.setFieldText(fieldText);
    tableField.setFieldName(NameUtil.asFieldName(fieldText));
    tableField.setTypeText(typeText);
    tableField.setFunName(NameUtil.asClassName(fieldText));
    if (nullable.equals("Y")) {
      tableField.setNullable("true");
    } else {
      tableField.setNullable("false");
    }
    if (typeText.contains("CHAR") | typeText.contains("TEXT")) {
      tableField.setType("String");
    } else if (typeText.contains("NUMBER") | typeText.contains("INT")) {
      tableField.setType("Integer");
    } else if (typeText.contains("DATE") | typeText.contains("TIME") | typeText.contains("LONG")) {
      tableField.setType("Long");
    } else if (typeText.contains("BLOB")) {
      tableField.setType("Byte[]");
    } else if (typeText.contains("DOUBLE")) {
      tableField.setType("Double");
    } else if (typeText.contains("FLOAT")) {
      tableField.setType("Float");
    } else if (typeText.contains("CLOB")) {
      tableField.setType("String");
    } else {
      tableField.setType("Object");
    }
    return tableField;
  }
}
